<include file="Public/header"/> 
<include file="Public/sidebar"/>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        产品管理
        <small>产品列表</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
        <li class="active">Here</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="box">
            <div class="box-header">
            <a href="{:U('Admin/Product/add')}"><button class="btn btn-success">添加产品</button></a>
            </div>
            <!-- /.box-header -->
            <form action="{:U('Admin/Product/order')}" method="post">
            <div class="box-body">
              <table id="example2" class="table table-bordered table-hover mailbox-messages">
                <thead>
                <tr>
                  <td></td>
                  <th>排序</th>
                  <th>产品标题</th>
                  <th>分类</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="post" item="v">
                <tr>

                  <td style="width:20px;height:25px;"><label><input name="dell[]" class="checktoall" style="width:40px;height:25px;" type="checkbox" value="{$v.id}"></label></td>

                  <td style="width:60px;height:25px;"><input type="text" class="form-control" style="width:60px;height:25px;" type="text" name="{$v['id']}" value="{$v['order_number']}"></td>
                  <td>{$v['name']}</td>
                  <td>{$v['category_name']}</td>
                  <td><a href="{:U('Admin/Product/edit',array('id'=>$v['id']))}">修改</a> | <a href="{:U('Admin/Product/copy',array('id'=>$v['id']))}">复制</a> | <a href="javascript:if(confirm('确定删除？'))location='{:U('Admin/Product/delete',array('id'=>$v['id']))}'">删除</a></td>
                </tr>
                </foreach>
                <tr>
                  <th><a class="btn btn-success" href="javascript:select()">全选</a></th>
                  <th><a class="btn btn-success"  href="javascript:fanselect()">反选</a></th>
                  <th><a class="btn btn-success" href="javascript:noselect()">全不选</a> | <a class="btn btn-success" id="delall" href="javascript:;" >删除所选</a> | <input class="btn btn-success" type="submit" value="排序"></th>
                  <th></th>
                  <th></th>
                </tr>
                </tbody>
              </table>
            </div>
            </form>
            <!-- /.box-body -->
            {$page}

      </div>

      <!-- /.box -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
<include file="Public/footer"/>
<script type="text/javascript">
  $(document).ready(function() {

    $('#delall').click(function(){
      if (  confirm('确认删除所选？') ){
          var check_value = [];
          $("input:checkbox.checktoall").each(function() {
            if (this.checked) {
              check_value.push($(this).val());
            }
          });
          $.ajax({
                    type:"post",
                    url:"{:U("Admin/Product/delAll")}",
                    data:{
                        "new_id": check_value
                    },//可有可无
                    dataType:"json",//可有可无
                    async:false,//取消异步请求
                    success:function(data){
                        alert(data);
                        location.reload();
                    },
                    error:function(){
                        alert("删除失败");
                    }
          }); 
      } 
    });


  });

    var checkall=document.getElementsByName("dell[]");
    function select(){                          //全选
      for(var $i=0;$i<checkall.length;$i++){
        checkall[$i].checked=true;
      }
    }
    function fanselect(){                        //反选
      for(var $i=0;$i<checkall.length;$i++){
        if(checkall[$i].checked){
          checkall[$i].checked=false;
        }else{
          checkall[$i].checked=true;
        }
      }
    }         
    function noselect(){                          //全不选
      for(var $i=0;$i<checkall.length;$i++){
        checkall[$i].checked=false;
      }
    }

</script>